<template>
  <div v-loading="loading" class="panel-2" style="position: relative;">
    <div class="title" style="width: 50%;">
      <div>风机频率（Hz）<!-- <span class="sub_tit">当前CO<sub>2</sub>浓度：最高88ppm</span> --></div>
    </div>
    <LineChart ref="chart" style="position:absolute; left: 0; top: 0;z-index: 1;" />
  </div>
</template>

<script>
import { getFjFrequency } from '@/api/fjgs/statistic.js'
import LineChart from './LineChart.vue'
import { groupBy } from 'loadsh'

export default {
  components: {
    LineChart
  },
  props: {
    queryParams: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false
    }
  },
  watch: {
    queryParams: {
      handler: 'getData',
      deep: true
    //   immediate: true
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      this.loading = true
      getFjFrequency(this.queryParams).then(res => {
        console.log(res.data)
        const source = {}
        const equ_names = []
        // // res.data ===>>source
        // // {
        // //   "15:00":{ "time": "15:00", "1号风机": 2145, "2号风机": 2451 },
        // //   "16:00":{ "time": "16:00", "1号风机": 2123.5,"2号风机": 2222 }
        // // }
        res.data.forEach(e => {
          if (!equ_names.includes(e.equ_name)) {
            equ_names.push(e.equ_name)
          }
          if (source[e.time]) {
            source[e.time][e.equ_name] = e.value
          } else {
            source[e.time] = {
              time: e.time,
              [e.equ_name]: e.value
            }
          }
        })

        this.$refs.chart.updateChart1({
          dataset: {
            source: Object.values(source)
          },
          series: new Array(equ_names.length).fill({
            type: 'line'
          })
        })
        this.loading = false
      })
    }
  }
}
</script>

  <style lang="scss" scoped>
  @import url('./style.scss');
  </style>

